# -*- coding: utf-8 -*-
"""
@Env 
@Time 2024/9/3 下午2:39
@Author yzpang
@Function:  基础配置
"""
import os
import logging


def get_logger():
    # 日志格式
    LOG_FORMAT = "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s"

    # 日志存储路径
    LOG_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "logs")
    if not os.path.exists(LOG_PATH):
        os.mkdir(LOG_PATH)

    # 日志配置
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    # 文件处理器
    file_handler = logging.FileHandler(os.path.join(LOG_PATH, "logs.log"))
    file_handler.setLevel(logging.INFO)

    # 控制台处理器
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.INFO)

    logging.basicConfig(format=LOG_FORMAT, handlers=[file_handler, console_handler])
    return logger
